package com.wondersgroup.framework.widget.taglib.form;

import com.wondersgroup.framework.widget.annotations.WidgetTagAttribute;
import com.wondersgroup.framework.widget.library.extjs.ExtComponent;
import com.wondersgroup.framework.widget.library.extjs.form.ExtSlider;
import com.wondersgroup.framework.widget.library.html.Div;
import com.wondersgroup.framework.widget.library.html.HtmlComponent;
import com.wondersgroup.framework.widget.util.OutputUtils;
import com.wondersgroup.framework.widget.util.TagUtils;
import javax.servlet.jsp.JspException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;

public class SliderTag extends BaseInputTag {
	private String buddy;
	private int minValue = 0;
	private int maxValue = 100;
	private int step = 10;
	private String snap;
	private boolean tipable = true;
	private String tiptext;
	private int scale;
	private boolean vertical;
	private String width = "214";
	private String height = "0";

	public int getMinValue() {
		return this.minValue;
	}

	@WidgetTagAttribute(description = "滑动条起始处（最底部）的值，默认值为0")
	public void setMinValue(int paramInt) {
		this.minValue = paramInt;
	}

	public int getMaxValue() {
		return this.maxValue;
	}

	@WidgetTagAttribute(description = "滑动条最大的值，默认值为100")
	public void setMaxValue(int paramInt) {
		this.maxValue = paramInt;
	}

	public int getStep() {
		return this.step;
	}

	@WidgetTagAttribute(description = "滑动条滑动一格代表的值，默认值为10")
	public void setStep(int paramInt) {
		this.step = paramInt;
	}

	public boolean isTipable() {
		return this.tipable;
	}

	@WidgetTagAttribute(description = "滑动条选择时，是否进行滑动条当前滑块值提示，默认为true")
	public void setTipable(boolean paramBoolean) {
		this.tipable = paramBoolean;
	}

	public String getTiptext() {
		return this.tiptext;
	}

	@WidgetTagAttribute(description = "当前滑块值提示的值，可以自定义选择的值，默认只显示滑动条当前滑块的值")
	public void setTiptext(String paramString) {
		this.tiptext = paramString;
	}

	public boolean isVertical() {
		return this.vertical;
	}

	@WidgetTagAttribute(description = "是否纵向显示，默认的值为false")
	public void setVertical(boolean paramBoolean) {
		this.vertical = paramBoolean;
	}

	public String getWidth() {
		return this.width;
	}

	@WidgetTagAttribute(description = "当滑动条横向显示时的宽度，默认为214")
	public void setWidth(String paramInt) {
		this.width = paramInt;
	}

	public String getHeight() {
		return this.height;
	}

	@WidgetTagAttribute(description = "当滑动条纵向显示时的高度，默认为0")
	public void setHeight(String paramInt) {
		this.height = paramInt;
	}

	public void processStartTagContent() throws JspException {
		Div localDiv = new Div(getId() + "_div");
		ExtSlider localExtSlider = new ExtSlider(getId());
		BeanUtils.copyProperties(this, localExtSlider);
		localExtSlider.setRenderTo(localDiv.getId());
		if (isTipable()) {
			if (StringUtils.isEmpty(getTiptext())) {
				localExtSlider.setPlugins("new Ext.ux.SliderTip()");
			} else {
				localExtSlider.setPlugins("new Ext.ux.SliderTip({getText: function(slider){ return String.format('"
						+ getTiptext() + "', slider.getValue());}})");
			}	
		}
			
		StringBuffer localStringBuffer = new StringBuffer();
		localStringBuffer.append(OutputUtils.writeJSFile(this.pageContext, new String[] { "wonders/form/wonders-form-min.js" }));
		localStringBuffer.append(OutputUtils.writeHTML(new HtmlComponent[] { localDiv }));
		localStringBuffer.append(OutputUtils.ExtOnReady(new ExtComponent[] { localExtSlider }));
		TagUtils.getInstance().write(this.pageContext, localStringBuffer.toString());
	}
}